package cn.lijiajia3515.cairo.captcha.image;

import cn.lijiajia3515.cairo.captcha.Captcha;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.springframework.http.MediaType;

import java.time.Duration;

/**
 * 图片验证码
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
public class ImageCaptcha implements Captcha {

	/**
	 * 标识
	 */
	private String id;

	/**
	 * 图片字节数组
	 */
	private ImageCaptchaDetail detail;

	/**
	 * 验证码
	 */
	private String code;

	/**
	 * 过期时间
	 */
	private Duration expire;

	/**
	 * 图片验证码 详情
	 */
	@Data
	@Accessors(chain = true)
	@NoArgsConstructor
	@AllArgsConstructor
	@Builder(toBuilder = true)
	public static class ImageCaptchaDetail {
		/**
		 * 类型
		 */
		private MediaType mediaType;

		/**
		 * 字节
		 */
		private byte[] bytes;
	}

	@Override
	public ImageCaptchaDetail getDetail() {
		return detail;
	}

	@Override
	public String getCode() {
		return code;
	}

	@Override
	public Duration getExpire() {
		return expire;
	}

}

